Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Add document:mCreate#64

Merged
scottinet merged 22 commits into
3-devfrom
KZL-1350-document-mCreate
Mar 6, 2020
Merged

Add document:mCreate#64
scottinet merged 22 commits into
3-devfrom
KZL-1350-document-mCreate

Conversation

@y-abs
Copy link
Copy Markdown
Contributor

@y-abs y-abs commented Feb 21, 2020

What does this PR do ?

This PR implements the mCreate method with its unit tests.

How should this be manually tested?

Clone this branch and run unit tests
./gradlew test

When it succeed, compile it

./gradlew jar

Initiate another java project by adding the compiled SDK as a dependency.

Then, run Kuzzle, create an index nyc-open-data and a yellow-taxi collection in the admin console.
Finally, run this code

import io.kuzzle.sdk.*;
import io.kuzzle.sdk.Options.KuzzleOptions;
import io.kuzzle.sdk.Options.Protocol.WebSocketOptions;
import io.kuzzle.sdk.Protocol.WebSocket;

import java.util.concurrent.ConcurrentHashMap;

public class mCreateDocument {
    private static Kuzzle kuzzle;

    public static void main(String[] args) {
        WebSocketOptions opts = new WebSocketOptions();
        opts.setAutoReconnect(true).setConnectionTimeout(42000);

        try {
            WebSocket ws = new WebSocket("localhost", opts);

            kuzzle = new Kuzzle(ws, (KuzzleOptions) null);

            kuzzle.connect();

            ConcurrentHashMap<String, Object> document1 = new ConcurrentHashMap<>();
            ConcurrentHashMap<String, Object> body1 = new ConcurrentHashMap<>();

            ConcurrentHashMap<String, Object> document2 = new ConcurrentHashMap<>();
            ConcurrentHashMap<String, Object> body2 = new ConcurrentHashMap<>();

            document1.put("_id", "some-id1");
            body1.put("key", "value");
            document1.put("body", body1);

            document2.put("_id", "some-id2");
            body2.put("key", "value");
            document2.put("body", body2);

            ArrayList<ConcurrentHashMap<String, Object>> documents = new ArrayList<>();
            documents.add(document1);
            documents.add(document2);

            ConcurrentHashMap<String, Object> response =
            kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents)
            .get();

            System.out.println(response);
        }  catch (Exception e) {
            e.printStackTrace();
        }

        kuzzle.disconnect();
    }
};

You should see the documents in your collection.

@y-abs y-abs self-assigned this Feb 21, 2020
Copy link
Copy Markdown
Contributor

@scottinet scottinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also report changes requested in #55, #59 and #61

| Arguments | Type | Description |
| ------------------ | -------------------------------------------- | --------------------------------- |
| `_id` | <pre>String</pre> (optional) | Optional document ID. Will be auto-generated if not defined. |
| `body` | <pre>Boolean</pre> (optional) | Document body |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong type

| `index` | <pre>String</pre> | Index |
| `collection` | <pre>String</pre> | Collection |
| `documents` | <pre>ArrayList<ConcurrentHashMap<String, Object>></pre> | ArrayList containing the documents to create |
| `waitForRefresh` | <pre>Boolean</pre> | Optional parameters |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong parameter description


## Return

A `ConcurrentHashMap` which has a `successes` and `errors` array:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must provide the exact type for the successes and errors values, otherwise they aren't usable

Comment thread doc/3/controllers/document/m-create/index.md
@y-abs y-abs requested a review from scottinet February 26, 2020 16:28
ConcurrentHashMap<String, ArrayList<Object>> response = kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents)
.get();

System.out.println("Successfully created " + response.get("successes").size() + " documents");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do the snippet test on something from the result as well as for the other methods?

Also can you add the result of the println in comment?
It helps developer to better apprehend the structure of the response object they have. We try to do this for every method (Look the Javascript SDK and Doc)

@y-abs y-abs requested a review from Aschen February 28, 2020 14:13
@y-abs y-abs force-pushed the KZL-1350-document-mCreate branch from d37a222 to 49a0997 Compare March 4, 2020 16:06
Makes it easier to read in documentation pages
Comment thread doc/3/controllers/document/m-create/index.md
@scottinet scottinet merged commit 26c378c into 3-dev Mar 6, 2020
@scottinet scottinet deleted the KZL-1350-document-mCreate branch March 6, 2020 09:31
@jenow jenow mentioned this pull request May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants